<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>同步修改异步修改的过程</title>
</head>
<body>
    
    <script>
    
    
        {
            // 同步修改的过程 

            let state = {
                data: {
                    name: 'wang'
                }
            };

            function syncChange (obj) {
                for (const key in obj) {
                    if (obj.hasOwnProperty(key)) {
                        obj[key] = 'change';
                    }
                }
            }

            function asyncChange (obj) {
                setTimeout(() => {
                    for (const key in obj) {
                        if (obj.hasOwnProperty(key)) {
                            obj[key] = 'async change';
                        }
                    }
                }, 2000);
            }

            syncChange(state);
            
            console.log('sync',state);
            
            asyncChange (state);

            setTimeout(() => {
                console.log('async',state);
            }, 3000);



        }
    
    
    </script>
</body>
</html>